//
//  ContentView.m
//  PentahoIPPUC
//
//  Created by Bill Seyler on 6/14/10.
//  Copyright 2010 Pentaho Corporation. All rights reserved.
//

#import "ContentView.h"
#import "SolutionNode.h"
#import "PentahoIPPUCAppDelegate.h"

#define kViewURIFragment		@"ViewAction?solution=%@&path=%@&action=%@&userid=@&password=@"

@implementation ContentView
@synthesize contentView;
@synthesize contentNode;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	PentahoIPPUCAppDelegate *delegate = (PentahoIPPUCAppDelegate*)[[UIApplication sharedApplication] delegate];
	NSString *urlStr = [NSString stringWithFormat:@"%@%@", [delegate serverUrl], kViewURIFragment];
	urlStr = [NSString stringWithFormat:urlStr, [contentNode solution], [contentNode path], [contentNode fileName], [delegate userid], [delegate password]];
	if ([contentNode url]) {
		NSLocale *currentUserLocale = [NSLocale currentLocale];
		urlStr = [contentNode url];
		NSMutableArray *dest = [NSMutableArray arrayWithArray:[urlStr pathComponents]];
		[dest removeObjectAtIndex:1];
		urlStr = [NSString pathWithComponents:dest];
		urlStr = [[delegate serverUrl] stringByAppendingString:urlStr];
		urlStr = [urlStr stringByReplacingOccurrencesOfString:@"{locale}" withString:[currentUserLocale localeIdentifier]];
		urlStr = [urlStr stringByAppendingString:[NSString stringWithFormat:@"&userid=%@&password=%@", [delegate userid], [delegate password]]];
	}
	NSLog(@"Request: %@", urlStr);
	NSURL *url = [[NSURL alloc] initWithString:urlStr];
	[contentView loadRequest:[NSURLRequest requestWithURL:url]];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
